package com.cw1.principle.segregation2;

/**
 * 接口隔离原则
 * @author Administrator
 */
public class Segregation {
    public static void main(String[] args) {
        // 实现接口隔离原则
        /*
        * 通过调用接口来实现调用接口实现类的方法
        * 接口使用什么方法，指向实现类的方法
        * */
        A a = new A();
        a.depend1(new B());
        a.depend2(new B());
        a.depend3(new B());

        a.depend4(new D());
        a.depend5(new D());
    }
}


interface interFace1{
    void operation1();
}


interface interFace2{
    void operation2();
    void operation3();
}

interface interFace3{
    void operation4();
    void operation5();
}

class B implements  interFace1,interFace2{
    public void operation1() {
        System.out.println("B类实现方法operation1");
    }

    public void operation2() {
        System.out.println("B类实现方法operation2");
    }

    public void operation3() {
        System.out.println("B类实现方法operation3");
    }
}

class D implements interFace1,interFace3{

    public void operation1() {
        System.out.println("D类实现方法operation1");
    }

    public void operation4() {
        System.out.println("D类实现方法operation4");
    }

    public void operation5() {
        System.out.println("D类实现方法operation5");
    }
}

class A {
    public void depend1(interFace1 interFace1){
        interFace1.operation1();
    }

    public void depend2(interFace2 interFace2){
        interFace2.operation2();
    }

    public void depend3(interFace2 interFace2){
        interFace2.operation3();
    }

    public void depend4(interFace3 interFace3){
        interFace3.operation4();
    }

    public void depend5(interFace3 interFace3){
        interFace3.operation5();
    }
}